package com.yeban.javase.day08.test02;

import com.sun.xml.internal.bind.v2.TODO;
/** @Desc TODO
 * @Author yeban
 * @Date 2025/10/16
 *
 *  1.账户或密码不能为空
 *  2.账户与密码不匹配
 */
class Demo {

    public static void main(String[] args) {

        System.out.println("---------- 信息正确情况 ----------");
        try {
            login(20251001L,"张三");
        } catch (LoginException e) {
            System.out.println(e.getMessage());
        }
        System.out.println("---------- 信息错误情况 ----------");
        try {
            login(20251004L,"张三");
        } catch (LoginException e) {
            System.out.println(e.getMessage());
        }
    }

    public static boolean checkNull(String str) throws LoginException {
        if (str == null || str.trim().isEmpty()) {
            throw new LoginException("账户或密码不能为空");
        }
        return true;
    }

    public static Account login(Long id, String password) throws LoginException {
        ArrayDao dao = new ArrayDao();
        if (id == null) {
            throw new LoginException("账户或密码不能为空");
        }
        checkNull(password);

        // 查询
        Account acc = dao.selectOne(id, password);
        if (acc != null) {
            System.out.println("登录成功！欢迎您！");
            return acc;
        } else {
            throw new LoginException("账户与密码不匹配");
        }
    }
}

class Account {
    private Long id;
    private String password;

    public Account() {
    }

    public Account(Long id, String password) {
        this.id = id;
        this.password = password;
    }

    /**
     * 获取
     * @return id
     */
    public Long getId() {
        return id;
    }

    /**
     * 设置
     * @param id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * 获取
     * @return password
     */
    public String getPassword() {
        return password;
    }

    /**
     * 设置
     * @param password
     */
    public void setPassword(String password) {
        this.password = password;
    }

    public String toString() {
        return "Account{id = " + id + ", password = " + password + "}";
    }
}
